package com.wgb.movie.model.vo;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.wgb.movie.model.entity.MovieShow;
import com.wgb.movie.model.entity.SeatStatus;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 上映视图
 *
 * @author <a href="https://github.com/liyupi">程序员鱼皮</a>
 * @from <a href="https://www.code-nav.cn">编程导航学习圈</a>
 */
@Data
public class MovieShowVO implements Serializable {

    /**
     * 放映ID
     */
    private Long id;

    /**
     * 电影 id
     */
    private Long movieId;

    private MovieVO movieVO;

    /**
     * 影院 id
     */
    private Long theaterId;

    private TheaterVO theaterVO;

    /**
     * 放映时间
     */
    private Date showTime;

    /**
     * 语言类型（0-国语，1-英语）
     */
    private Integer languageType;

    /**
     * 影厅类型（0-1D，1-2D）
     */
    private Integer hallType;

    /**
     * 售价
     */
    private BigDecimal price;

    /**
     * 座位
     */
    private List<SeatStatus> seats;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;


    /**
     * 封装类转对象
     *
     * @param movieShowVO
     * @return
     */
    public static MovieShow voToObj(MovieShowVO movieShowVO) {
        if (movieShowVO == null) {
            return null;
        }
        MovieShow movieShow = new MovieShow();
        BeanUtils.copyProperties(movieShowVO, movieShow);
        movieShow.setSeats(JSONUtil.toJsonStr(movieShowVO.getSeats()));
        return movieShow;
    }

    /**
     * 对象转封装类
     *
     * @param movieShow
     * @return
     */
    public static MovieShowVO objToVo(MovieShow movieShow) {
        if (movieShow == null) {
            return null;
        }
        MovieShowVO movieShowVO = new MovieShowVO();
        BeanUtils.copyProperties(movieShow, movieShowVO);
        movieShowVO.setSeats(JSONUtil.toList(movieShow.getSeats(), SeatStatus.class));
        return movieShowVO;
    }
}
